package com.ylkj.patient.rnmodule;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.core.content.PermissionChecker;

import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import com.baidu.mobstat.StatService;
import com.donkingliang.imageselector.utils.ImageSelector;
import com.examination.mlib.baseold.ModulesBaseApp;
import com.examination.mlib.constants.ARouterConstants;
import com.examination.mlib.constants.AllStringConstants;
import com.examination.mlib.constants.PatientUrl;
import com.examination.mlib.constants.ProjectConfigure;
import com.examination.mlib.constants.UserInfoConstants;
import com.examination.mlib.db.DBOpenHelper;
import com.examination.mlib.db.DataBaseUtil;
import com.examination.mlib.interfaceapi.NetWorkCallBack;
import com.examination.mlib.manager.PermissionManager;
import com.examination.mlib.utils.PDFUtils;
import com.examination.mlib.view.preview.PreviewBuilder;
import com.example.homemodule.model.bean.DoctorHealthBean;
import com.example.messagemodule.MessageHelper;
import com.example.messagemodule.utils.MessageUtils;
import com.example.minemodule.entity.MediaEntity;
import com.example.minemodule.entity.VideoEntity;
import com.facebook.react.bridge.BaseActivityEventListener;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.modules.core.PermissionListener;
import com.google.gson.Gson;
import com.luck.picture.lib.compress.Luban;
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.users.rn.kit.bridge.impl.route.KitRouterModule;
import com.users.rn.rncommon.ui.RNActivity;
import com.users.rn.rncommon.ui.RNSingTaskActivity;
import com.users.rn.rncommon.util.RNPageUtil;
import com.yilijk.base.AppBase;
import com.yilijk.base.network.RequestParams;
import com.yilijk.base.network.https.HttpCallBack;
import com.yilijk.base.network.https.HttpUtils;
import com.yilijk.base.network.https.NetAttestationUtils;
import com.yilijk.base.utils.ALog;
import com.yilijk.base.utils.ActivityManagerUtils;
import com.yilijk.base.utils.BitmapUtils;
import com.yilijk.base.utils.ClickUtils;
import com.yilijk.base.utils.CommonUtils;
import com.yilijk.base.utils.DevicesUtils;
import com.yilijk.base.utils.LoadingUtils;
import com.yilijk.base.utils.RSAUtils;
import com.yilijk.base.utils.SharedPreferencesUtils;
import com.yilijk.dialog.AlertDialogManager;
import com.yilijk.dialog.callback.AlertDialogimpl;
import com.yljk.live.common.utils.MediaCountyManager;
import com.examination.mlib.interfaceapi.MessageApi;
import com.examination.mlib.view.SuspendedBallView;
import com.yljk.mcbase.MCBase;
import com.ylkj.patient.BuildConfig;
import com.ylkj.patient.MainApplication;
import com.ylkj.patient.MyActivityManager;
import com.ylkj.patient.R;
import com.ylkj.patient.entity.AddressEntity;
import com.ylkj.patient.entity.ImagesListBean;
import com.ylkj.patient.entity.UserInfoEntity;
import com.ylkj.patient.entity.WXpayData;
import com.ylkj.patient.pickview.PickerView;
import com.ylkj.patient.scheme.SchemeTools;
import com.ylkj.patient.amap.PoiInfo;
import com.ylkj.patient.ui.activities.MainActivity;
import com.ylkj.patient.utils.AMapLocationUtils;
import com.ylkj.patient.utils.AppReactUtils;
import com.ylkj.patient.utils.PayUtils;
import com.ylkj.patient.utils.PushMessageUtil;
import com.ylkj.patient.utils.SearchSpUtils;
import com.ylkj.patient.utils.ThreeSDKInitUtils;
import com.ylkj.patient.utils.UmengUtils;
import com.ylkj.patient.utils.WXShareUtils;
import com.ylkj.patient.wxapi.WXEntryActivity;

import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import yxscan.webviewpdf.PDFActivity;

import static android.app.Activity.RESULT_OK;
import static androidx.core.content.FileProvider.getUriForFile;
import static com.examination.mlib.constants.ProjectConfigure.debugFun;


public class RNRouterModule extends KitRouterModule {

    private static final int REQUEST_CODE = 0x00000011;
    public static final int REQUEST_CODE_ADDRESS = 0x00000012;
    private static final int CAMERA_CODE = 0x00000013;
    private final String LOGIN_SUCCESS = "loginsuccess";
    private final String ThreePartiesLogin_WeChat = "weixin";
    private final String TYPE_ALBUME = "album";
    private final String TYPE_ALBUME_HEAD = "uploadAvator";
    private final String DATASTORAGE = "dataStorage";
    private final String LOCAL_DB = "localDatabase";
    private final String GETDATASTORAGE = "getDataStorage";
    private final String BACKTOROOTVC = "backToRootVC";
    private final String REFRESH = "refresh";
    private final String LOGOUT = "logout";
    private final String markMessageAsRead = "markMessageAsRead";
    private final String GET_DATASTOREDELETE = "localStorage";
    private final String SAVAPICTURE = "savepicture";
    private final String WXSHARE = "wxShare";
    private final String SAVADRUGPICTURE = "saveDrugPicture";
    private final String GENEREATESHAREPICTURE = "generateSharePicture";
    private final String WXPAY = "wxPay";
    private final String CHANGE_ADDRESS = "changeAddress";
    private final String VIDEOANDMEDIA = "RnToNativePage";
    private final String PLAYVIDEO = "RnToNativePlayVideo";
    private final String CHATING = "chating";
    private final String InquiryRecord = "inquiryRecord";
    private final String UserAgreeChecked = "userAgreeChecked";
    private final String POP2 = "POP2";
    private final String EXPLAIN_ACTION = "ExplainAction";
    private final String CLICK_PUSH_MESSAGE = "clickPushMessage";
    private final String REDIRECT_TO_LOGIN = "redirectToLogin";


    private Handler handler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
//            if (msg.what == 1) {
//                tencentLocationManager.removeUpdates(tencentLocationListener);
//
//            }
        }
    };


    private ArrayList<Activity> rnActivitys = new ArrayList<>();

    private static HashMap<String, String> temporaryDataStorage = new HashMap<>();

    public static HashMap<String, String> getTemporaryDataStorage() {
        return temporaryDataStorage;
    }

    @Override
    public void dispatchScheme(@NotNull ReactContext reactContext, @NotNull String scheme, @NotNull String pageTag, @NotNull Promise promise) {
        SchemeTools.getInstance().execScheme(reactContext, scheme);
    }

    /**
     * 获取状态栏高度
     *
     * @param readableMap
     * @param promise     StatusH 状态栏高度
     *                    NavH 顶部导航栏高度
     *                    TabH 底部导航栏高度
     *                    SafeH 底部安全区域高度
     */
    @Override
    public void getEnvironmentNavigationHeight(@NotNull ReadableMap readableMap, @NotNull Promise promise) {
        /**
         * 状态栏
         * 顶部导航
         * 底部导航
         * 底部安全区域
         */
        int StatusH = 0;
        int NavH = 0;
        int TabH = 0;
        int SafeH = 0;
        //获取状态栏高度
        int resourceId = MainApplication.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            StatusH = MainApplication.getContext().getResources().getDimensionPixelSize(resourceId);
        }

//        TabH = CommonUtils.dip2px(MainApplication.getContext(), 70);
//        NavH = CommonUtils.dip2px(MainApplication.getContext(), 40);
        //创建map对象回调
        Gson gson = new Gson();
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("StatusH", StatusH);
        stringObjectHashMap.put("NavH", 40);
        stringObjectHashMap.put("TabH", 70);
        stringObjectHashMap.put("SafeH", 0);
        String s = gson.toJson(stringObjectHashMap);
        ALog.d("get", "getEnvironmentNavigationHeight: " + s);
        promise.resolve(s);

    }

    private BaseActivityEventListener baseActivityEventListener;
    private File outputImage;
    private Uri imageUri;
    private String imagePath;

    private void getNativeImage(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {

        String type = readableMap.getString("type"); //类型
        switch (type) {
            //上传头像
            case TYPE_ALBUME:
                int number = readableMap.getInt("number"); //数量
                boolean isTailoring = false;
                if (readableMap.hasKey("isTailoring")) {
                    isTailoring = readableMap.getBoolean("isTailoring");
                }
                //相册
                if (isTailoring) {
                    //单选并剪裁
                    ImageSelector.builder()
                            .useCamera(true) // 设置是否使用拍照
                            .setCrop(true)  // 设置是否使用图片剪切功能。
                            .setCropRatio(1.0f) // 图片剪切的宽高比,默认1.0f。宽固定为手机屏幕的宽。
                            .setSingle(true)  //设置是否单选
                            .canPreview(true) //是否点击放大图片查看,，默认为true
                            .start(reactContext.getCurrentActivity(), REQUEST_CODE); // 打开相册
                } else {
                    //多选(最多9张)
                    ImageSelector.builder()
                            .useCamera(true) // 设置是否使用拍照
                            .setSingle(false)  //设置是否单选
                            .canPreview(true) //是否点击放大图片查看,，默认为true
                            .setMaxSelectCount(number) // 图片的最大选择数量，小于等于0时，不限数量。
                            .start(reactContext.getCurrentActivity(), REQUEST_CODE); // 打开相册
                }
                break;
            default:
                //拍照
                String state = Environment.getExternalStorageState();
                if (state.equals(Environment.MEDIA_MOUNTED)) {
                    String path = Environment.getExternalStorageDirectory().getPath();
                    //创建拍摄图片的目录
                    File file = new File(path + "/Pictures/");
                    if (!file.exists()) {
                        if (!file.mkdirs()) {
                            //目录创建失败
                        }
                    }
                    imagePath = file.getAbsolutePath() + "/" + "h1tx" + System.currentTimeMillis() + ".jpg";
                    outputImage = new File(imagePath);
                    //拍照后原图回存入此路径
                    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
                        imageUri = Uri.fromFile(outputImage);
                    } else {
                        //7.0 调用系统相机拍照不再允许使用Uri方式，应该替换为FileProvider
                        imageUri = getUriForFile(reactContext, "com.ylkj.patient.fileprovider", outputImage);
                    }
                    //启动相机拍照
                    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
                    reactContext.getCurrentActivity().startActivityForResult(intent, CAMERA_CODE);
                    break;
                }
        }
        //rnactivity回调
        baseActivityEventListener = new BaseActivityEventListener() {
            @Override
            public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
                super.onActivityResult(activity, requestCode, resultCode, data);
                if (requestCode == REQUEST_CODE && data != null) {
                    ArrayList<String> images = data.getStringArrayListExtra(ImageSelector.SELECT_RESULT);
                    Flowable.just(images)
                            .observeOn(Schedulers.io())
                            .map(list -> {
                                List<File> files =
                                        Luban.with(reactContext.getCurrentActivity())
                                                .load(list)
                                                .setTargetDir(reactContext.getCurrentActivity().getExternalCacheDir().getAbsolutePath())
                                                .ignoreBy(100)
                                                .get();
                                if (files == null) {
                                    files = new ArrayList<>();
                                }
                                return files;
                            })
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(new Consumer<List<File>>() {
                                @Override
                                public void accept(List<File> files) throws Exception {
                                    String[] uris = new String[files.size()];
                                    ALog.i("imagePath", "onActivityResult: " + images.size());
                                    ALog.i("imagePath", "onActivityResult: " + uris.length);
                                    for (int i = 0; i < files.size(); i++) {
                                        ALog.d("imagePath", "onActivityResult: " + files.get(i).getPath());
                                        String path = files.get(i).getPath();
                                        Uri pa = Uri.fromFile(new File(path));//根据路径转化为uri
                                        ALog.d("imagePath", "onActivityResult: " + pa.toString());
                                        uris[i] = path;
                                    }
                                    HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                                    stringObjectHashMap.put("image", uris);
                                    stringObjectHashMap.put("result", true);
                                    String s = new Gson().toJson(stringObjectHashMap);
                                    promise.resolve(s);
                                }
                            });
                } else if (requestCode == CAMERA_CODE && resultCode == RESULT_OK) {
                    //CAMERA_CODE
                    BitmapUtils.addMediaStore(reactContext, outputImage, imagePath);
                    String[] strings = new String[]{imagePath};
                    ArrayList<String> images = new ArrayList<>();
                    for (int i = 0; i < strings.length; i++) {
                        images.add(strings[i]);
                    }
                    Flowable.just(images)
                            .observeOn(Schedulers.io())
                            .map(list -> {
                                List<File> files =
                                        Luban.with(reactContext.getCurrentActivity())
                                                .load(list)
                                                .setTargetDir(reactContext.getCurrentActivity().getExternalCacheDir().getAbsolutePath())
                                                .ignoreBy(100)
                                                .get();
                                if (files == null) {
                                    files = new ArrayList<>();
                                }
                                return files;
                            })
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(new Consumer<List<File>>() {
                                @Override
                                public void accept(List<File> files) throws Exception {
                                    String[] uris = new String[files.size()];
                                    ALog.i("imagePath", "onActivityResult: " + images.size());
                                    ALog.i("imagePath", "onActivityResult: " + uris.length);
                                    for (int i = 0; i < files.size(); i++) {
                                        ALog.d("imagePath", "onActivityResult: " + files.get(i).getPath());
                                        String path = files.get(i).getPath();
                                        Uri pa = Uri.fromFile(new File(path));//根据路径转化为uri
                                        ALog.d("imagePath", "onActivityResult: " + pa.toString());
                                        uris[i] = path;
                                    }
                                    HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                                    stringObjectHashMap.put("image", uris);
                                    stringObjectHashMap.put("result", true);
                                    String s = new Gson().toJson(stringObjectHashMap);
                                    promise.resolve(s);
                                }
                            });

                } else {
                    HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                    stringObjectHashMap.put("image", null);
                    stringObjectHashMap.put("result", true);
                    String s = new Gson().toJson(stringObjectHashMap);
                    promise.resolve(s);
                }
                reactContext.removeActivityEventListener(baseActivityEventListener);
            }
        };
        reactContext.addActivityEventListener(baseActivityEventListener);

    }

    /**
     * 获取图片
     *
     * @param reactContext
     * @param readableMap
     * @param promise
     */
    @Override
    public void getImageAction(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        //打开相册 返回本地图片路径
        //判断权限是否存在
        String[] permissionArray = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
        boolean permissionWriteExternal = PermissionChecker.checkSelfPermission(reactContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
        boolean permissionReadExternal = PermissionChecker.checkSelfPermission(reactContext, Manifest.permission.READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
        boolean permissionCamera = PermissionChecker.checkSelfPermission(reactContext, Manifest.permission.CAMERA) == PermissionChecker.PERMISSION_GRANTED;
        ALog.e("oakPermission", "getImageAction ====> " + permissionWriteExternal + " " + permissionReadExternal + " " + permissionCamera);

        if (!(permissionWriteExternal && permissionReadExternal && permissionCamera)) {
//            HashMap<String, Object> stringObjectHashMap = new HashMap<>();
//            stringObjectHashMap.put("result", false);
//            stringObjectHashMap.put("msg", "应用相机/相册权限受限,请在手机设置中启用!");
//            String s = new Gson().toJson(stringObjectHashMap);
//            promise.resolve(s);
            if (reactContext.getCurrentActivity() != null && reactContext.getCurrentActivity() instanceof RNActivity) {
                RNActivity rnActivity = (RNActivity) reactContext.getCurrentActivity();
                rnActivity.requestPermissions(permissionArray, 1001, new PermissionListener() {
                    @Override
                    public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
                        ALog.e("oakPermission", "permission result: " + requestCode + " " + new Gson().toJson(permissions) + " " + new Gson().toJson(grantResults));
                        if (requestCode == 1001) {
                            boolean isAllGrant = true;
                            for (int grantResult : grantResults) {
                                if (grantResult == PermissionChecker.PERMISSION_GRANTED) {
                                    continue;
                                }
                                isAllGrant = false;
                                break;
                            }
                            if (isAllGrant) {
                                getNativeImage(reactContext, readableMap, promise);
                            } else {
                                HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                                stringObjectHashMap.put("result", false);
                                stringObjectHashMap.put("msg", "应用相机/相册权限受限,请在手机设置中启用!");
                                String s = new Gson().toJson(stringObjectHashMap);
                                promise.resolve(s);
                            }
                        }
                        return false;
                    }
                });

            } else {
                PermissionManager.getInstance()
                        .get(reactContext.getCurrentActivity())
                        .requestPermissions(
                                permissionArray
                                ,
                                new String[]{"允许应用使用文件存储权限", "允许应用使用文件访问权限", "允许应用使用相机权限"})
                        .requestCodes(0xa1)
                        .setmRequestPermissionCallBack(new PermissionManager.RequestPermissionCallBack() {
                            @Override
                            public void noM() {

                            }

                            @Override
                            public void granted() {
                                getNativeImage(reactContext, readableMap, promise);
                            }

                            @Override
                            public void denied() {

                                HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                                stringObjectHashMap.put("result", false);
                                stringObjectHashMap.put("msg", "应用相机/相册权限受限,请在手机设置中启用!");
                                String s = new Gson().toJson(stringObjectHashMap);
                                promise.resolve(s);
                            }
                        })
                        .request();
            }
        } else {
            getNativeImage(reactContext, readableMap, promise);
        }

    }


    @Override
    public void getLocationInformation(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        boolean type = false;
        if (readableMap != null && readableMap.hasKey("type")) {
            type = readableMap.getBoolean("type");
        }
        boolean finalType = type;

        String[] permissionArray = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
        boolean permissionLocation = PermissionChecker.checkSelfPermission(reactContext, Manifest.permission.ACCESS_FINE_LOCATION) == PermissionChecker.PERMISSION_GRANTED;
        if (!permissionLocation) {
            if (reactContext.getCurrentActivity() != null && reactContext.getCurrentActivity() instanceof RNActivity) {
                RNActivity rnActivity = (RNActivity) reactContext.getCurrentActivity();
                rnActivity.requestPermissions(permissionArray, 1002, new PermissionListener() {
                    @Override
                    public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
                        ALog.e("oakPermission", "permission result: " + requestCode + " " + new Gson().toJson(permissions) + " " + new Gson().toJson(grantResults));
                        if (requestCode == 1002) {
                            boolean isAllGrant = true;
                            for (int grantResult : grantResults) {
                                if (grantResult == PermissionChecker.PERMISSION_GRANTED) {
                                    continue;
                                }
                                isAllGrant = false;
                                break;
                            }
                            if (isAllGrant) {
                                AMapLocationUtils.getLocalInfo(promise);
                            } else {
                                HashMap<String, Object> hashMap = new HashMap<>();
                                hashMap.put("result", finalType ? true : false);
                                hashMap.put("location", null);
                                promise.resolve(new Gson().toJson(hashMap));
                            }
                        }
                        return false;
                    }
                });
            } else {
                PermissionManager.getInstance()
                        .get(reactContext.getCurrentActivity())
                        .requestPermissions(
                                permissionArray
                                ,
                                new String[]{"允许应用使用位置权限"})
                        .requestCodes(0xa1)
                        .setmRequestPermissionCallBack(new PermissionManager.RequestPermissionCallBack() {
                            @Override
                            public void noM() {

                            }

                            @Override
                            public void granted() {
                                AMapLocationUtils.getLocalInfo(promise);
                            }

                            @Override
                            public void denied() {
                                HashMap<String, Object> hashMap = new HashMap<>();
                                hashMap.put("result", finalType ? true : false);
                                hashMap.put("location", null);
                                promise.resolve(new Gson().toJson(hashMap));
                            }
                        })
                        .request();
            }
        } else {
            AMapLocationUtils.getLocalInfo(promise);
        }


    }

    private void getLocalInfo(@NotNull Promise promise) {
        AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
        mLocationOption.setOnceLocation(true);
        mLocationOption.setOnceLocationLatest(true);
        //初始化定位
        AMapLocationClient mLocationClient = new AMapLocationClient(MainApplication.getContext());
        AMapLocationListener mAMapLocationListener = new AMapLocationListener() {
            @Override
            public void onLocationChanged(AMapLocation amapLocation) {
                if (amapLocation != null) {
                    if (amapLocation.getErrorCode() == 0) {
//可在其中解析amapLocation获取相应内容。
                        amapLocation.getLatitude();//获取纬度
                        amapLocation.getLongitude();//获取经度
                        amapLocation.getCity();//城市信息
                        JSONArray newArray = new JSONArray();
                        newArray.put(amapLocation.getCity());
                        newArray.put(amapLocation.getLatitude() + "");
                        newArray.put(amapLocation.getLongitude() + "");
                        String address = amapLocation.getAddress();
                        String province = amapLocation.getProvince();
                        String city = amapLocation.getCity();
                        String district = amapLocation.getDistrict();
                        String street = amapLocation.getStreet();
                        double latitude = amapLocation.getLatitude();
                        double longitude = amapLocation.getLongitude();
                        HashMap<String, Object> hashMap = new HashMap<>();
                        hashMap.put("result", true);
                        hashMap.put("address", address);
                        if (!TextUtils.isEmpty(province) && province.endsWith("市")) {
                            hashMap.put("province", province.substring(0, province.length() - 1));
                        } else {
                            hashMap.put("province", province);
                        }
                        //                    hashMap.put("province", province.endsWith("市") ? province.substring(0, province.length() - 1) : province);
                        hashMap.put("city", city);
                        if (TextUtils.isEmpty(district)) {
                            district = city;
                        }
                        hashMap.put("district", district);
                        hashMap.put("street", street);
                        hashMap.put("latitude", latitude);
                        hashMap.put("longitude", longitude);
                        ALog.e("定位时间", "getLocationInformation");
                        promise.resolve(new Gson().toJson(hashMap));
                    }
                } else {
                    //定位失败时，可通过ErrCode（错误码）信息来确定失败的原因，errInfo是错误信息，详见错误码表。
//                    Toast.makeText(getApplicationContext(),"定位获取失败,请检查是否开启定位权限",Toast.LENGTH_SHORT).show();
                }
            }
        };
//设置定位回调监听
        mLocationClient.setLocationListener(mAMapLocationListener);
        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption);
//启动定位
        mLocationClient.startLocation();
    }

    /**
     * 加载客服
     *
     * @param reactContext
     * @param readableMap
     * @param promise
     */
    @Override
    public void openCustomerService(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        String moorType = "";
        String moorId = "";
        if (readableMap.hasKey("moorType")) {
            moorType = readableMap.getString("moorType");
        }
        if (TextUtils.isEmpty(moorType)) {
            moorType = "common";
        } else {
            switch (moorType) {
                case "common": {
                    break;
                }
                case "doctor": {
                    if (readableMap.hasKey("doctorId")) {
                        moorId = readableMap.getString("doctorId");
                    }
                    break;
                }
                case "drug": {
                    if (readableMap.hasKey("drugId")) {
                        moorId = readableMap.getString("drugId");
                    }
                    break;
                }
                case "packet": {
                    if (readableMap.hasKey("packetId")) {
                        moorId = readableMap.getString("packetId");
                    }
                    break;
                }
                case "order": {
                    if (readableMap.hasKey("orderId")) {
                        moorId = readableMap.getString("orderId");
                    }
                    break;
                }
                case "chargeOrder": {
                    if (readableMap.hasKey("orderId")) {
                        moorId = readableMap.getString("orderId");
                    }
                    break;
                }
            }
        }
        if (!TextUtils.isEmpty(moorId)) {
            ARouter.getInstance().build(ARouterConstants.ContractWebviewActivity)
                    .withString("title", "在线客服")
                    .withBoolean("isShowLoading", true)
                    .withString("moorType", moorType)
                    .withString("moorId", moorId)
                    .navigation();
        } else {
            ARouter.getInstance().build(ARouterConstants.ContractWebviewActivity)
                    .withString("title", "在线客服")
                    .withBoolean("isShowLoading", true)
                    .withString("moorType", moorType)
                    .navigation();
        }
    }

    /**
     * 打开网页
     *
     * @param reactContext
     * @param readableMap
     * @param promise
     */
    @Override
    public void openNativeWeb(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        String s = AppReactUtils.INSTANCE.delNativeMap(readableMap.toString());
        Map maps = (Map) JSON.parse(s);
        String title = (String) maps.get("title");
        String url = (String) maps.get("content");
        String type = (String) maps.get("type");
        String rnTypeWeb = (String) maps.get("rnTypeWeb");
        if ("helpH5".equals(type)) {
            String faqId = (String) maps.get("faqId");
            String weburl = HttpUtils.getWebUrl() + "/index.html?t=" + System.currentTimeMillis() + "#/faq-detail?id=" + faqId + "&tk=" + DevicesUtils.getToken();
            ALog.e(weburl);
            ARouter.getInstance().build(ARouterConstants.MineWebviewActivity)
                    .withString("title", title)
                    .withString("url", weburl)
                    .withString("rnTypeWeb", rnTypeWeb)
                    .withBoolean("ishtml", false)
                    .navigation();
        } else if (url.endsWith(".pdf")) {
            PermissionManager.getInstance()
                    .get(reactContext.getCurrentActivity())
                    .requestPermissions(
                            new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}
                            ,
                            new String[]{"允许应用使用文件存储权限", "允许应用使用文件访问权限"})
                    .requestCodes(0xa1)
                    .setmRequestPermissionCallBack(new PermissionManager.RequestPermissionCallBack() {
                        @Override
                        public void noM() {

                        }

                        @Override
                        public void granted() {
                            Intent intent = new Intent();
                            intent.setClass(reactContext.getCurrentActivity(), PDFActivity.class);
                            intent.putExtra("url", url);
                            intent.putExtra("title", title);
                            intent.putExtra("isOpenFile", true);
                            reactContext.getCurrentActivity().startActivity(intent);
                        }

                        @Override
                        public void denied() {

                        }
                    })
                    .request();

        } else {
            if (url.startsWith("http")) {
                ARouter.getInstance().build(ARouterConstants.MineWebviewActivity)
                        .withString("title", title)
                        .withString("url", url)
                        .withString("rnTypeWeb", rnTypeWeb)
                        .withBoolean("ishtml", false)
                        .navigation();
            } else {
                ARouter.getInstance().build(ARouterConstants.MineWebviewActivity)
                        .withString("title", title)
                        .withString("url", url)
                        .withString("rnTypeWeb", rnTypeWeb)
                        .withBoolean("ishtml", true)
                        .navigation();
            }

        }

    }

    /**
     * 拨打电话
     *
     * @param reactContext
     * @param readableMap
     * @param promise
     */

    @Override
    public void openTelprompt(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {

        String[] permissionArray = new String[]{Manifest.permission.CALL_PHONE};
        boolean permissionPhone = PermissionChecker.checkSelfPermission(reactContext, Manifest.permission.CALL_PHONE) == PermissionChecker.PERMISSION_GRANTED;
        if (!permissionPhone) {
            if (reactContext.getCurrentActivity() != null && reactContext.getCurrentActivity() instanceof RNActivity) {
                RNActivity rnActivity = (RNActivity) reactContext.getCurrentActivity();
                rnActivity.requestPermissions(permissionArray, 1004, new PermissionListener() {
                    @Override
                    public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
                        ALog.e("oakPermission", "permission result: " + requestCode + " " + new Gson().toJson(permissions) + " " + new Gson().toJson(grantResults));
                        if (requestCode == 1004) {
                            boolean isAllGrant = true;
                            for (int grantResult : grantResults) {
                                if (grantResult == PermissionChecker.PERMISSION_GRANTED) {
                                    continue;
                                }
                                isAllGrant = false;
                                break;
                            }
                            if (isAllGrant) {
                                gotoOpenTel(readableMap, reactContext);
                            } else {
//                                try {
//                                    jsonObject.put("result", false);
//                                    jsonObject.put("msg", "检测到您还没有打开相册保存权限，请前往手机设置开启相册权限！");
//                                    jsonObject.put("filePath", "");
//                                } catch (JSONException e) {
//                                    e.printStackTrace();
//                                }
//                                promise.resolve(jsonObject.toString());
                            }
                        }
                        return false;
                    }
                });
            } else {
                PermissionManager.getInstance()
                        .get(reactContext.getCurrentActivity())
                        .requestPermissions(
                                permissionArray
                                ,
                                new String[]{"允许应用使用拨打电话权限"})
                        .requestCodes(0xa1)
                        .setmRequestPermissionCallBack(new PermissionManager.RequestPermissionCallBack() {
                            @Override
                            public void noM() {

                            }

                            @Override
                            public void granted() {
                                gotoOpenTel(readableMap, reactContext);
                            }

                            @Override
                            public void denied() {

                            }
                        })
                        .request();
            }
        } else {
            gotoOpenTel(readableMap, reactContext);
        }

    }

    private void gotoOpenTel(@NonNull ReadableMap readableMap, @NonNull ReactContext reactContext) {
        String s = readableMap.toString();
        JSONObject dataJsonObject = null;
        String tel = null;
        try {
            dataJsonObject = new JSONObject(s);
            String nativeMap = dataJsonObject.getString("NativeMap");
            JSONObject dataJsonObject1 = new JSONObject(nativeMap);
            tel = dataJsonObject1.getString("tel");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        ArrayList<String> tels = new ArrayList<>();
        tels.add(tel);

        AppReactUtils.INSTANCE.openPhoneView(reactContext.getCurrentActivity(), tels);
    }

    /**
     * 设置状态栏颜色
     *
     * @param readableMap
     */
    @SuppressLint("LongLogTag")
    @Override
    public void setEnvironmentStatusType(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap) {

//        RNActivity rnActivity = (RNActivity) reactContext.getCurrentActivity();

        boolean isWhite = readableMap.getBoolean("isWhite");
//        UI更新设置在主线程
        if (isWhite) {
            ALog.d("true", "setEnvironmentStatusType: ");
            //状态栏信息设置-黑色
            //获取窗口区域
            handler.post(new Runnable() {
                @Override
                public void run() {
                    AppReactUtils.INSTANCE.setAndroidNativeLightStatusBar(reactContext.getCurrentActivity(), isWhite);
                    AppReactUtils.INSTANCE.setStatusBarColor(reactContext.getCurrentActivity(), Color.parseColor("#000000"));
                }
            });

        } else {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    //设置状态栏颜色
//                        window.setStatusBarColor(UIUtils.getColor(reactContext,Color.WHITE));
                    //设置显示为白色背景，黑色字体
//                        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                    AppReactUtils.INSTANCE.setStatusBarColor(reactContext.getCurrentActivity(), Color.parseColor("#000000"));

                }
            });
            ALog.d("false", "setEnvironmentStatusType: ");
        }
    }

    /**
     * 展示Scan二维码
     *
     * @param reactContext
     * @param readableMap
     * @param promise
     */
    @Override
    public void showNativeScan(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        promise.resolve("true");

    }

    /**
     * 展示pickView
     *
     * @param reactContext
     * @param readableMap
     * @param promise
     */
    @Override
    public void showPickView(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        HashMap<String, Object> map = new HashMap<>();
        String mark = readableMap.getString("mark");
        String type = readableMap.getString("type");
        String title = readableMap.getString("title");
        ReadableArray data = readableMap.getArray("data");

        map.put("mark", mark);
        map.put("type", type);
        map.put("title", title);


        HashMap<String, Object> dataMap = new HashMap<>();
        List<String> list = new ArrayList<>();
        if (data != null && data.size() != 0) {
            for (int i = 0; i < data.size(); i++) {
                list.add(data.getString(i));
            }
        } else {
            list = null;
        }
        dataMap.put("data", list);
        map.put("data", dataMap);
        handler.post(new Runnable() {
            @Override
            public void run() {
                PickerView.getInstance(MyActivityManager.getInstance().getCurrentActivity()).getPicker(map, MyActivityManager.getInstance().getCurrentActivity(), promise);
            }
        });
    }

    /**
     * 第三方登录
     *
     * @param reactContext
     * @param readableMap
     * @param promise
     */
    @Override
    public void threePartiesLogin(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        //获取登录类型
        String threePartiesLogin_type = readableMap.getString("type");
        if (threePartiesLogin_type.equals(ThreePartiesLogin_WeChat)) {

            //微信登录
//            WeChatUtils.INSTANCE.wechatLogin(reactContext);
            if (!MainApplication.iwxapi.isWXAppInstalled()
                    && !CommonUtils.isWeixinAvilible(MainApplication.getContext())) {
                Toast.makeText(reactContext, "微信未安装，请先安装微信", Toast.LENGTH_SHORT).show();
            }
            SendAuth.Req req = new SendAuth.Req();
            req.scope = "snsapi_userinfo";
            req.state = "wechat_sdk_demo_test";
            MainApplication.iwxapi.sendReq(req);
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction(AllStringConstants.BroadcastReceiver);
            reactContext.registerReceiver(new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    if (intent.getStringExtra("wechatCode") != null) {
                        ALog.d("微信授权成功", "onReceive: ");
                        String wechatCode = intent.getStringExtra("wechatCode");
                        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                        stringObjectHashMap.put("code", wechatCode);
                        stringObjectHashMap.put("type", "weixin");
                        stringObjectHashMap.put("result", true);
                        stringObjectHashMap.put("deviceNo", SharedPreferencesUtils.getInstance().getUment_String("deviceToken", null));
                        ALog.d("onReceive", "onReceive: " + CommonUtils.getModuleCommonUtils().GsontoString(stringObjectHashMap));
                        promise.resolve(CommonUtils.getModuleCommonUtils().GsontoString(stringObjectHashMap));
                    }
                }
            }, intentFilter);
//            UMShareConfig config = new UMShareConfig();
//            config.isNeedAuthOnGetUserInfo(true);
//            UMShareAPI.get(reactContext).setShareConfig(config);
//            UMShareAPI.get(MainApplication.getContext()).getPlatformInfo(reactContext.getCurrentActivity(), SHARE_MEDIA.WEIXIN, new UMAuthListener() {
//                @Override
//                public void onStart(SHARE_MEDIA share_media) {
//
//                }
//
//                @Override
//                public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
//                    ALog.d("Map", "onComplete: "+map.toString());
//                }
//
//                @Override
//                public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
//
//                }
//
//                @Override
//                public void onCancel(SHARE_MEDIA share_media, int i) {
//
//                }
//            });
        }
//        promise.resolve("true");
    }

    private BaseActivityEventListener toNativeGeneralActionEventListener;

    /**
     * 通用方法
     *
     * @param reactContext
     * @param readableMap
     * @param promise
     */
    @Override
    public void toNativeGeneralAction(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        ALog.i("toNativeGeneralAction", "toNativeGeneralAction: " + readableMap);
        String readableMapString = AppReactUtils.INSTANCE.delNativeMap(readableMap.toString());
        String dataString = null;
        JSONObject dataJson = null;
        if (readableMap.hasKey("data")) {
            try {
                dataString = new JSONObject(readableMapString).getString("data");
                ALog.d("toNativeGeneralAction", "toNativeGeneralAction: " + dataString);
                dataJson = new JSONObject(dataString);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        switch (readableMap.getString(AllStringConstants.tag)) {
            case LOGIN_SUCCESS: {//登录成功
                UserInfoEntity userInfoEntity = new Gson().fromJson(dataString, UserInfoEntity.class);
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.token, userInfoEntity.getToken());
                UserInfoEntity.AccountBean account = userInfoEntity.getAccount();
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_id, account.getId());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.imAccount, account.getImAccount());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.imPassword, account.getImPassword());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_type, account.getType());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_outId, account.getOutId());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_openId, account.getOpenId());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_customerId, account.getCustomerId());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_passportId, account.getPassportId());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_createTime, account.getCreateTime());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_updateTime, account.getUpdateTime());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_mobile, account.getMobile());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_accountName, account.getAccountName());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_password, account.getPassword());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_salt, account.getSalt());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_source, account.getSource());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_imgUrl, account.getImgUrl());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_lastLoginTime, account.getLastLoginTime());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_nickName, account.getNickName());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_userNo, account.getUserNo());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_mobileAes, account.getMobileAes());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_passportAes, account.getPassportAes());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_deleteFlag, account.getDeleteFlag());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_deviceNo, account.getDeviceNo());
                SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_deviceType, account.getDeviceType());
                SharedPreferencesUtils.getInstance().saveLoginTag(UserInfoConstants.account_tagLoggedIn, true);
                ARouter.getInstance().build(ARouterConstants.CenterActivity).navigation();
                StatService.setAuthorizedState(MainApplication.getContext(), true);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        UmengUtils.addUmengAddAlias(MainApplication.getContext());
                    }
                });
                getTemporaryDataStorage().clear();
                Intent login = new Intent(AllStringConstants.BroadcastLogin);
                reactContext.sendBroadcast(login);      //发送广播
                MediaCountyManager.getInstance().appLogin();
            }
            break;
            case LOCAL_DB: {
                String fileName = "";
                String type = "";
                String dataDb = "";
                String nameKey = "";

                try {
                    if (readableMap.hasKey("fileName")) {
                        fileName = readableMap.getString("fileName");
                        ALog.e("oakkkdb", "filename: " + fileName);
                    }
                    if (readableMap.hasKey("type")) {
                        type = readableMap.getString("type");
                        ALog.e("oakkkdb", "type: " + type);
                    }
                    if (readableMap.hasKey("data")) {
                        dataDb = readableMap.getString("data");
                        ALog.e("oakkkdb", "data: " + dataDb);
                    }
                    if (readableMap.hasKey("nameKey")) {
                        nameKey = readableMap.getInt("nameKey") + "";
                        ALog.e("oakkkdb", "nameKey: " + nameKey);
                    }


                    switch (type) {
                        case "updateData": {

                            boolean result = false;
                            if (!TextUtils.isEmpty(nameKey)) {
                                result = DataBaseUtil.getInstance().updateData(MainApplication.getMainApplication(), fileName, dataDb, nameKey);
                            } else {
                                result = DataBaseUtil.getInstance().updateData(MainApplication.getMainApplication(), fileName, dataDb);
                            }

                            HashMap<String, Object> hashMap = new HashMap<>();
                            hashMap.put("isSuccess", result);
                            promise.resolve(CommonUtils.getModuleCommonUtils().GsontoString(hashMap));

                            break;
                        }
                        case "setData": {

                            boolean result = false;
                            if (!TextUtils.isEmpty(nameKey)) {
                                result = DataBaseUtil.getInstance().setData(MainApplication.getMainApplication(), fileName, dataDb, nameKey);
                            } else {
                                result = DataBaseUtil.getInstance().setData(MainApplication.getMainApplication(), fileName, dataDb);
                            }

                            HashMap<String, Object> hashMap = new HashMap<>();
                            hashMap.put("isSuccess", result);
                            promise.resolve(CommonUtils.getModuleCommonUtils().GsontoString(hashMap));

                            break;
                        }
                        case "getData": {

                            String dataValue = "";
                            if (!TextUtils.isEmpty(nameKey)) {
                                dataValue = DataBaseUtil.getInstance().getData(MainApplication.getMainApplication(), fileName, nameKey);
                            } else {
                                dataValue = DataBaseUtil.getInstance().getData(MainApplication.getMainApplication(), fileName);
                            }
                            HashMap<String, Object> hashMap = new HashMap<>();
                            if (!TextUtils.isEmpty(dataValue)) {
                                ALog.e("oakkkdb", "datavalue: " + dataValue);
                                hashMap.put("isSuccess", true);
                                hashMap.put("data", dataValue);
                            } else {
                                hashMap.put("isSuccess", false);
                            }
                            promise.resolve(CommonUtils.getModuleCommonUtils().GsontoString(hashMap));

                            break;
                        }
                        case "removeData": {
                            if (!TextUtils.isEmpty(nameKey)) {
                                DataBaseUtil.getInstance().removeData(MainApplication.getMainApplication(), fileName, nameKey);
                            } else {
                                DataBaseUtil.getInstance().removeData(MainApplication.getMainApplication(), fileName);
                            }
                            HashMap<String, Object> hashMap = new HashMap<>();
                            hashMap.put("isSuccess", true);
                            promise.resolve(CommonUtils.getModuleCommonUtils().GsontoString(hashMap));

                            break;
                        }

                    }

                } catch (Throwable e) {
                    e.printStackTrace();
                    ALog.e("oakkkdb", "error: " + e.getMessage());
                } finally {
                    ALog.e("oakkkdb", "finally: ");
                }
            }
            break;
            case DATASTORAGE: {
                //设置密码
                try {
                    if (dataJson.has(UserInfoConstants.token)) {
//                    ALog.i("token", "toNativeGeneralAction: "+readableMap.getString(AllStringConstants.token));
                        SharedPreferencesUtils.getInstance().save(UserInfoConstants.token, dataJson.getString(UserInfoConstants.token));

                    }
                    if (dataJson.has(UserInfoConstants.account_openId)) {
                        SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_openId, dataJson.getString(UserInfoConstants.account_openId));
                    }
                    if (dataJson.has(UserInfoConstants.account_mobile)) {
                        SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_mobile, dataJson.getString(UserInfoConstants.account_mobile));
                    }
                    if (dataJson.has(UserInfoConstants.account_nickName)) {
                        SharedPreferencesUtils.getInstance().save(UserInfoConstants.account_nickName, dataJson.getString(UserInfoConstants.account_nickName));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            break;
            case GETDATASTORAGE: {//返回给rn数据
                HashMap<String, Object> userMap = new HashMap<>();

                userMap.put("passportId", SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_passportId, ""));
                userMap.put("id", SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_id, ""));
                userMap.put("imAccount", SharedPreferencesUtils.getInstance().getString(UserInfoConstants.imAccount, ""));
                userMap.put("imPassword", SharedPreferencesUtils.getInstance().getString(UserInfoConstants.imPassword, ""));
                userMap.put("token", SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, ""));
                //患者openId 从本地读取返回RN
                userMap.put("openId", SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_openId, null));
                userMap.put("version", DevicesUtils.getVersionName());
                userMap.put("deviceId", DevicesUtils.getDeviceId());
                String maptoJson = CommonUtils.getModuleCommonUtils().getMaptoJson(userMap);
                promise.resolve(maptoJson);
            }
            break;
            case BACKTOROOTVC: {
                ARouter.getInstance().build(ARouterConstants.MAIN_ACTIVITY).navigation();
                reactContext.getCurrentActivity().finish();
            }
            break;
            case REFRESH: {
                //刷新
//                RNKITTools.INSTANCE.sendBroadcast(reactContext, "ReceiveRefreshKey", ReactUtils.INSTANCE.delNativeMap(readableMap.toString()));
            }
            break;
            case GET_DATASTOREDELETE: {
                StringBuffer stringBuffer = new StringBuffer();
                String fileName = null;
                String type = null;
                ArrayList<String> strings = new ArrayList<>();
                try {
                    fileName = readableMap.getString("fileName");
                    type = readableMap.getString("type");
                    String s1 = AppReactUtils.INSTANCE.delNativeMap(readableMap.toString());
                    JSONObject jsonObject = new JSONObject(s1);
                    JSONArray data1 = jsonObject.getJSONArray("data");
                    String history = SearchSpUtils.getInstance().getString(fileName, "");
                    stringBuffer.append(history);
                    for (int i = 0; i < data1.length(); i++) {
                        stringBuffer.append(data1.get(i) + "-");
                    }

                } catch (Exception e) {
                    CommonUtils.loginfo(e.getMessage());
                }
                ALog.i("toNativeGeneralAction", "toNativeGeneralAction: " + stringBuffer);

                switch (type) {
                    case "setData": {
                        SearchSpUtils.getInstance().save(fileName, stringBuffer.toString());
//                        SQLiteManager.getSqLiteManager().insertTableName(fileName,strings);

                        HashMap<String, Object> hashMap = new HashMap<>();
                        hashMap.put("isSuccess", "true");
                        promise.resolve(CommonUtils.getModuleCommonUtils().GsontoString(hashMap));
                        break;
                    }
                    case "getData": {
                        ArrayList<String> strings2 = new ArrayList<>();
                        strings2.clear();
                        int count = readableMap.getInt("count");
                        String string = SearchSpUtils.getInstance().getString(fileName, null);
                        ALog.i("toNativeGeneralAction" + count, "toNativeGeneralAction: " + string);
                        if (string == null) {
                            strings2.clear();
                        } else {
                            String[] split = string.split("-");
                            int index = 0;
                            index = split.length;
//                            if (count < 0) {
//                                index = split.length;
//                            } else if (split.length > count) {
//                                index = count;
//                            } else {
//                                index = split.length;
//                            }

                            ALog.i("toNativeGeneralAction", "toNativeGeneralAction: " + index);
                            for (int i = 0; i < index; i++) {
                                if (split[i] != null) {
                                    strings2.add(split[i]);
                                }
                            }
                        }
                        ArrayList<String> finaldata = new ArrayList<>();
                        for (int i = strings2.size() - 1; i >= 0; i--) {
                            boolean flag = false;
                            for (int j = 0; j < finaldata.size(); j++) {
                                if (finaldata.get(j).equals(strings2.get(i))) {
                                    flag = true;
                                }
                            }
                            if (!flag) {
                                finaldata.add(strings2.get(i));
                            }
                        }
                        ArrayList<String> tempList = new ArrayList<>();
                        if (count < 0) {
                            for (int i = 0; i < finaldata.size(); i++) {
                                tempList.add(finaldata.get(i));
                            }
                        } else if (finaldata.size() > count) {
                            for (int i = 0; i < count; i++) {
                                tempList.add(finaldata.get(i));
                            }
                        } else {
                            tempList.addAll(finaldata);
                        }
                        HashMap<String, Object> hashMap = new HashMap<>();
                        hashMap.put("isSuccess", type);
                        hashMap.put("data", tempList);
                        promise.resolve(CommonUtils.getModuleCommonUtils().GsontoString(hashMap));
                        break;
                    }
                    case "removData": {
                        SearchSpUtils.getInstance().removekey(fileName);
                        ALog.i("删除", "toNativeGeneralAction: ");
                        promise.resolve("{\"isSuccess\":true}");
                        break;
                    }
                }
            }
            break;
            case REDIRECT_TO_LOGIN: {
                MediaCountyManager.getInstance().appLogout();
                MessageUtils.logoutIM();
                Intent loginintent = new Intent(AllStringConstants.BroadcastReceiver);
                loginintent.putExtra(AllStringConstants.islogin, true);         //向广播接收器传递数据
                reactContext.sendBroadcast(loginintent);      //发送广播

                if (SharedPreferencesUtils.getInstance().removeAll()) {
                    ActivityManagerUtils.finishAllActivity();
                    ARouter.getInstance().build(ARouterConstants.CenterActivity).navigation();
                }
            }
            break;
            case LOGOUT: {
//                MediaCountyManager.getInstance().appLogout();
//                MessageUtils.logoutIM();
//                Intent loginintent = new Intent(AllStringConstants.BroadcastReceiver);
//                loginintent.putExtra(AllStringConstants.islogin, true);         //向广播接收器传递数据
//                reactContext.sendBroadcast(loginintent);      //发送广播
////                ARouter.getInstance().build(ARouterConstants.MAIN_ACTIVITY).navigation();
//                if (SharedPreferencesUtils.getInstance().removeAll()) {
//                    ActivityManagerUtils.finishAllActivity();
//                    ARouter.getInstance().build(ARouterConstants.CenterActivity).navigation();
//                }
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        LoadingUtils.getLoadingUtils(reactContext.getCurrentActivity()).showLoading();
                    }
                });
                HttpUtils.post(AllStringConstants.mine_lagout, new HttpCallBack<String>() {
                    @Override
                    public void onSuccess(String s, int i) {
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                LoadingUtils.getLoadingUtils(reactContext.getCurrentActivity()).dismissLoading();

                                MediaCountyManager.getInstance().appLogout();
                                MessageUtils.logoutIM();
                                Intent loginintent = new Intent(AllStringConstants.BroadcastReceiver);
                                loginintent.putExtra(AllStringConstants.islogin, true);         //向广播接收器传递数据
                                reactContext.sendBroadcast(loginintent);      //发送广播
//                ARouter.getInstance().build(ARouterConstants.MAIN_ACTIVITY).navigation();
//                        if (SharedPreferencesUtils.getInstance().removeAll()) {
//                            ActivityManagerUtils.finishAllActivity();
//                            ARouter.getInstance().build(ARouterConstants.CenterActivity).navigation();
//                        }
                                if (SharedPreferencesUtils.getInstance().removeAll()) {
                                    NetAttestationUtils.getInstance().setSALT("");
                                    ActivityManagerUtils.finishAllActivity();
                                    ARouter.getInstance().build(ARouterConstants.CenterActivity).navigation();
                                }
                            }
                        });

                    }

                    @Override
                    public void onFailure(String s, int i) {

                    }
                });
            }
            break;
            case SAVAPICTURE: {

                //判断是否存在相册权限
                String imgUrl = readableMap.getString("imgUrl");
                JSONObject jsonObject = new JSONObject();

                String[] permissionArray = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
                boolean permissionWrite = PermissionChecker.checkSelfPermission(reactContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
                if (!permissionWrite) {
                    if (reactContext.getCurrentActivity() != null && reactContext.getCurrentActivity() instanceof RNActivity) {
                        RNActivity rnActivity = (RNActivity) reactContext.getCurrentActivity();
                        rnActivity.requestPermissions(permissionArray, 1003, new PermissionListener() {
                            @Override
                            public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
                                ALog.e("oakPermission", "permission result: " + requestCode + " " + new Gson().toJson(permissions) + " " + new Gson().toJson(grantResults));
                                if (requestCode == 1003) {
                                    boolean isAllGrant = true;
                                    for (int grantResult : grantResults) {
                                        if (grantResult == PermissionChecker.PERMISSION_GRANTED) {
                                            continue;
                                        }
                                        isAllGrant = false;
                                        break;
                                    }
                                    if (isAllGrant) {
                                        toSavePicture(imgUrl, reactContext, jsonObject, promise);
                                    } else {
                                        try {
                                            jsonObject.put("result", false);
                                            jsonObject.put("msg", "检测到您还没有打开相册保存权限，请前往手机设置开启相册权限！");
                                            jsonObject.put("filePath", "");
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        promise.resolve(jsonObject.toString());
                                    }
                                }
                                return false;
                            }
                        });
                    } else {

                        PermissionManager.getInstance()
                                .get(reactContext.getCurrentActivity())
                                .requestPermissions(
                                        permissionArray
                                        ,
                                        new String[]{"允许应用使用文件存储权限"})
                                .requestCodes(0xa1)
                                .setmRequestPermissionCallBack(new PermissionManager.RequestPermissionCallBack() {
                                    @Override
                                    public void noM() {

                                    }

                                    @Override
                                    public void granted() {
                                        toSavePicture(imgUrl, reactContext, jsonObject, promise);
                                    }

                                    @Override
                                    public void denied() {
                                        try {
                                            jsonObject.put("result", false);
                                            jsonObject.put("msg", "检测到您还没有打开相册保存权限，请前往手机设置开启相册权限！");
                                            jsonObject.put("filePath", "");
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        promise.resolve(jsonObject.toString());
                                    }
                                })
                                .request();
                    }
                } else {
                    toSavePicture(imgUrl, reactContext, jsonObject, promise);
                }

            }
            break;

            case WXSHARE: {
                /**
                 * 微信分享
                 * text 分享文本
                 * image 分享图片
                 * vide 分享音频
                 * h5 分享网页
                 */

                //判断微信是否安装
                if (!CommonUtils.isWeixinAvilible(MainApplication.getContext())) {
                    Toast.makeText(reactContext, "微信未安装，请先安装微信", Toast.LENGTH_SHORT).show();
                    return;
                }
                final String TEXT = "text";
                final String IMAGE = "image";
                final String VIDEO = "video";
                final String H5 = "h5";
                final String UNIAPP = "uniapp";
                String wxShare_type = readableMap.getString("type");
                String openId = readableMap.getString("openId");
                if (wxShare_type.equals(TEXT)) {
                    String text = readableMap.getString("text");
                    WXShareUtils.wxShareTxt(openId, text);
                } else if (wxShare_type.equals(IMAGE)) {
                    /**
                     * imgUrl
                     * openId
                     */
                    String imgUrl = readableMap.getString("imgUrl");
                    WXShareUtils.wxShareUrlImage(openId, imgUrl);
                } else if (wxShare_type.equals(VIDEO)) {
                    /**
                     * videoUrl  视频url
                     * videoTitle 视频标题
                     * videoDescription 视频描述
                     * openId
                     */

                    String videoUrl = readableMap.getString("videoUrl");
                    String videoTitle = readableMap.getString("videoTitle");
                    String videoDescription = readableMap.getString("videoDescription");
                    WXShareUtils.wxShareVideo(openId, videoUrl, videoTitle, videoDescription);
                } else if (wxShare_type.equals(H5)) {
                    /**
                     * webUrl 网页url
                     * webTitle 网页标题
                     * webDescription 网页描述
                     * openId
                     */

                    String webUrl = readableMap.getString("webUrl");
                    String webTitle = readableMap.getString("webTitle");
                    String webDescription = readableMap.getString("webDescription");
                    WXShareUtils.wxShareH5(openId, webUrl, webTitle, webDescription);
                } else if (wxShare_type.equals(UNIAPP)) {
                    /**
                     * 微信分享小程序
                     * @param webpageUrl  兼容低版本的网页链接
                     * @param userName   小程序原始id
                     * @param path    小程序页面路径
                     * @param title   小程序消息title
                     * @param description  小程序消息desc
                     * @param thumbBmp  小程序消息封面图片 小于128k 默认为LOGO
                     */
                    WXShareUtils.wxShareUniApp(
                            readableMap.getString("webpageUrl"),
                            readableMap.getString("userName"),
                            readableMap.getString("path"),
                            readableMap.getString("title"),
                            readableMap.getString("description"),
                            readableMap.getString("thumbBmp"));
                }
            }
            break;
            case SAVADRUGPICTURE: {
                //判断是否存在相册权限
                Boolean saveflag = PermissionChecker.checkSelfPermission(reactContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
                JSONObject savejsonObject = new JSONObject();
                if (!saveflag) {
                    try {
                        savejsonObject.put("result", false);
                        savejsonObject.put("msg", "检测到您还没有打开相册保存权限，请前往手机设置开启相册权限！");
                        savejsonObject.put("filePath", "");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    promise.resolve(savejsonObject.toString());
                    return;
                }

                try {
                    Bitmap bmp1;
                    if (readableMap.getString("imagrUrl").startsWith("https")) {
                        AppReactUtils.INSTANCE.createIgnoreVerifySSL("TLSv1.1");
                        bmp1 = BitmapUtils.GetImageInputStream(readableMap.getString("imagrUrl"));
                    } else {
                        bmp1 = BitmapFactory.decodeFile(readableMap.getString("imagrUrl"));
                    }

                    //  获取当前程序路径
                    String imagrUrl = readableMap.getString("imagrUrl");
                    String[] split = imagrUrl.split("/");
                    String s1 = split[split.length - 1];
                    MediaStore.Images.Media.insertImage(reactContext.getContentResolver(), bmp1, s1, "暂无");
                    //获得SD卡根目录路径
                    File externalStorageDirectory = Environment.getExternalStorageDirectory();
                    String sdpath = externalStorageDirectory.getAbsolutePath();
                    ALog.i("sdpath", "toNativeGeneralAction: " + sdpath + "/Pictures/" + s1);
                    savejsonObject.put("result", true);
                    savejsonObject.put("msg", "保存图片成功");
                    savejsonObject.put("filePath", sdpath + "/Pictures/" + s1);
                    promise.resolve(savejsonObject.toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                    try {
                        savejsonObject.put("result", false);
                        savejsonObject.put("msg", "保存图片失败");
                        savejsonObject.put("filePath", "");
                        promise.resolve(savejsonObject.toString());
                    } catch (JSONException jsonException) {
                        jsonException.printStackTrace();
                        promise.reject(jsonException);
                    }
                }
            }
            break;
            case GENEREATESHAREPICTURE: {
                //判断是否存在相册权限
                Boolean generateSharePictureflag = PermissionChecker.checkSelfPermission(reactContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
                JSONObject generateSharePicturejsonObject = new JSONObject();
                if (!generateSharePictureflag) {
                    try {
                        generateSharePicturejsonObject.put("result", false);
                        generateSharePicturejsonObject.put("msg", "检测到您还没有打开相册保存权限，请前往手机设置开启相册权限！");
                        generateSharePicturejsonObject.put("filePath", "");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    promise.resolve(generateSharePicturejsonObject.toString());
                    return;
                }

                String shareBg = null;
                String desc = null;
                String goodsUrl = null;
                String xcxLogo = null;
                String shareTitle = null;
                try {
                    shareBg = dataJson.getString("shareBg");
                    goodsUrl = dataJson.getString("goodsUrl");
                    desc = dataJson.getString("desc");
                    xcxLogo = dataJson.getString("xcxLogo");
                    shareTitle = dataJson.getString("shareTitle");
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                Bitmap bitmap = BitmapUtils.GetImageInputStream(shareBg);
                Bitmap bitmap1 = BitmapUtils.GetImageInputStream(goodsUrl);
                Bitmap bitmap2 = BitmapUtils.GetImageInputStream(xcxLogo);
                //背景图片缩放
                Bitmap newBg = BitmapUtils.zoomImg(bitmap, 690, 825);
                Bitmap newDrug = BitmapUtils.zoomImg(bitmap1, 320, 320);
                //设置圆角
                newDrug = BitmapUtils.makeRoundCorner(newDrug, 25);
                Bitmap newCode = BitmapUtils.zoomImg(bitmap2, 180, 180);
                Bitmap bitmap3 = BitmapUtils.mergeBitmapDrug(newBg, newDrug, newCode, desc, shareTitle);
                String dir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/com.ylkj.yljkproject/files/generateSharePicture.png";
                BitmapUtils.saveBitmap(bitmap3, dir);
                try {
                    generateSharePicturejsonObject.put("result", true);
                    generateSharePicturejsonObject.put("msg", "保存图片成功");
                    generateSharePicturejsonObject.put("filePath", dir);
                    promise.resolve(generateSharePicturejsonObject.toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                    promise.reject(e);
                }
            }
            break;
            case WXPAY: {
                IntentFilter filter = new IntentFilter(AllStringConstants.BroadcastReceiverForWXPay);
                reactContext.registerReceiver(new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        JSONObject result = new JSONObject();
                        try {
                            result.put("isSuccess", intent.getBooleanExtra("isSuccess", false));
                            promise.resolve(result.toString());
                        } catch (JSONException e) {
                            e.printStackTrace();
                            promise.reject(e);
                        }
                    }
                }, filter);
                WXpayData wxpayData = new Gson().fromJson(dataString, WXpayData.class);
                PayUtils.weixin(reactContext.getCurrentActivity(), wxpayData);
            }
            break;
            case CHANGE_ADDRESS: {
//                ARouter.getInstance().build(ARouterConstants.TencentMapActivity).navigation(reactContext.getCurrentActivity(), REQUEST_CODE_ADDRESS);
                ARouter.getInstance().build(ARouterConstants.AmapActivity).navigation(reactContext.getCurrentActivity(), REQUEST_CODE_ADDRESS);
            }
            break;
            case "Loading": {
                if (readableMap.hasKey("isLoading") && readableMap.getBoolean("isLoading")) {
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            String textStr = "";
                            if (readableMap.hasKey("text") && !TextUtils.isEmpty(textStr = readableMap.getString("text"))) {
                                LoadingUtils.getLoadingUtils(reactContext.getCurrentActivity()).showLoading(textStr);
                            } else {
                                LoadingUtils.getLoadingUtils(reactContext.getCurrentActivity()).showLoading();
                            }
                        }
                    });
                } else {
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            LoadingUtils.getLoadingUtils(reactContext.getCurrentActivity()).dismissLoading();
                        }
                    });

                }
            }
            break;
            case "baiduPOIsearch": {
                String searchText = readableMap.getString("searchText");
                String city = readableMap.getString("city");
                if (!TextUtils.isEmpty(searchText)) {
                    if (city != null && city.length() > 0) {
                        havaCitySearch(reactContext.getCurrentActivity(), city, searchText, promise);
                    } else {
                        noCitySearch(reactContext.getCurrentActivity(), searchText, promise);
                    }
                } else {
                    promise.resolve("");
                }
            }
            break;
            case VIDEOANDMEDIA: {
//                dataJson
                String videotype = readableMap.getString("type");
                switch (videotype) {
                    case "video": {
                        //video
                        VideoEntity videoEntity = new Gson().fromJson(dataString, VideoEntity.class);
                        if (videoEntity == null) {
                            Toast.makeText(reactContext, "数据为空", Toast.LENGTH_SHORT).show();
                        }
                        ARouter.getInstance().build(ARouterConstants.VideoInfoActivity).withSerializable("videoEntity", videoEntity).navigation();
                        break;
                    }
                    case "audio": {
                        //audio
                        MediaEntity mediaEntity = new Gson().fromJson(dataString, MediaEntity.class);
                        if (mediaEntity == null) {
                            Toast.makeText(reactContext, "数据为空", Toast.LENGTH_SHORT).show();
                        }
                        ARouter.getInstance().build(ARouterConstants.MediaPlayerActivity).withSerializable("mediaEntity", mediaEntity).navigation();
                        break;
                    }
                    case "toHome": {
                        Intent intent = new Intent(reactContext.getCurrentActivity(), MainActivity.class);
                        MainApplication.homeType = true;
                        reactContext.getCurrentActivity().startActivity(intent);
                        break;
                    }
                }

            }
            break;
            case PLAYVIDEO: {
                String url = readableMap.getString("url");
                if (url == null) {
                    Toast.makeText(reactContext, "数据为空", Toast.LENGTH_SHORT).show();
                }
                ARouter.getInstance().build(ARouterConstants.VideoInfoActivity).withSerializable("url", url).navigation();
            }
            break;
            case CHATING: {
                String doctorPassportId = readableMap.getString("doctorPassportId");
                if (!TextUtils.isEmpty(doctorPassportId) && !doctorPassportId.equals("null") && !doctorPassportId.equals("undefind")) {
                    long l = Long.valueOf(doctorPassportId).longValue();
                    ARouter.getInstance().build(ARouterConstants.ConversationActivity)
                            .withInt("chatTypeStatus", 0)
                            .withLong("doctorPassportId", l)
                            .withBoolean("isInquiryRecord", false).navigation();
                } else {
                    ALog.e("doctorPassportId 错误");
                }

            }
            break;
            case InquiryRecord: {
                String doctorPassportId = readableMap.getString("doctorPassportId");
                String chargesListId = readableMap.getString("chargesListId");
                long l = Long.valueOf(doctorPassportId).longValue();
                int i = Integer.valueOf(chargesListId).intValue();
                ARouter.getInstance().build(ARouterConstants.ConversationActivity)
                        .withLong("doctorPassportId", l)
                        .withInt("chargesListId", i)
                        .withInt("chatTypeStatus", 0)
                        .withBoolean("isInquiryRecord", true).navigation();
            }
            break;
            case "imLoging": {
                HashMap<String, Object> loginMap = new HashMap<>();
                if (!MessageUtils.isImLogin()) {
                    MessageUtils.imLogin(reactContext.getCurrentActivity(), new MessageApi() {
                        @Override
                        public void onSuccess(String data) {
                            loginMap.put("result", true);
                            loginMap.put("message", data);
                            promise.resolve(CommonUtils.getModuleCommonUtils().getMaptoJson(loginMap));
                        }

                        @Override
                        public void onError(String failInfo) {
                            loginMap.put("result", false);
                            loginMap.put("message", failInfo);
                            promise.resolve(CommonUtils.getModuleCommonUtils().getMaptoJson(loginMap));
                        }
                    });
                } else {
                    loginMap.put("result", true);
                    loginMap.put("message", "im已经登录");
                    promise.resolve(CommonUtils.getModuleCommonUtils().getMaptoJson(loginMap));
                }
            }
            break;
            case "push": {
                String pluginId = readableMap.getString("pluginId");
                String compontName = readableMap.getString("compontName");
                String data;
                Bundle bundle = new Bundle();
                Map<String, Object> parse = (Map<String, Object>) new com.alibaba.fastjson.JSONObject().parse(dataString);
                Iterator<Map.Entry<String, Object>> iterator = parse.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, Object> next = iterator.next();
                    bundle.putString(next.getKey(), String.valueOf(next.getValue()));
                }
                Intent intent = new Intent(reactContext, RNSingTaskActivity.class);
                intent.putExtra("intent_key_params", bundle);
                intent.putExtra("intent_key_plugin_id", pluginId);
                intent.putExtra("intent_key_module_id", "index");
                intent.putExtra("intent_key_component_name", compontName);
                bundle.putString("pageTag", RNPageUtil.createPageTag(pluginId, compontName));
                reactContext.getCurrentActivity().startActivity(intent);
            }
            break;
            case "RSAEncryption": {
                HashMap<String, Object> hashMap = new HashMap<>();
                String encryption = readableMap.getString("encryption");
                try {
                    hashMap.put("encryption", RSAUtils.encryptPublicKey(encryption));
                    promise.resolve(new Gson().toJson(hashMap));
                } catch (Exception e) {
                    e.printStackTrace();
                    promise.reject(e);
                }
            }
            break;
            case "temporarySetDataStorage": {
                // 临时存储- 存
                String dataKey = "";
                String dataValue = "";
                try {
                    dataKey = dataJson.getString("dataKey");
                    dataValue = dataJson.getString("dataValue");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                temporaryDataStorage.put(dataKey, dataValue);
                ALog.e("drugAdress", "tempStorage:" + new Gson().toJson(temporaryDataStorage));
            }
            break;
            case "temporaryGetDataStorage": {
                // 临时存储- 取
                String dataKey = "";
                try {
                    dataKey = dataJson.getString("dataKey");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                String dataValue = temporaryDataStorage.get(dataKey);
                if (dataValue == null) {
                    dataValue = "";
                }
                promise.resolve(dataValue);
            }
            break;
            case "BuriedPoint": {
                String actionID = "";
                String info = "";
                try {
                    actionID = dataJson.getString("actionID");
                    info = dataJson.getString("info");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                JSONObject infoJSON = null;
                try {
                    infoJSON = new JSONObject(info);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                ClickUtils.sendEvent(actionID, reactContext.getCurrentActivity(), true, infoJSON == null ? new JSONObject() : infoJSON);
            }
            break;
            case "creatPage": {
                rnActivitys.add(reactContext.getCurrentActivity());
                ALog.i("toNativeGeneralAction", "toNativeGeneralAction: " + rnActivitys.size());
            }
            break;
            case "finishMorePage": {
                String pageNumStr = readableMap.getString("pageNum");
                int pageNum = Integer.valueOf(pageNumStr).intValue();
                ALog.i("toNativeGeneralAction", "toNativeGeneralAction: " + rnActivitys.size());
                ALog.i("toNativeGeneralAction", "toNativeGeneralAction: " + pageNum);
                for (int i = rnActivitys.size() - 1; i >= rnActivitys.size() - pageNum && i >= 0; i--) {
                    if (!rnActivitys.get(i).isFinishing()) {
                        rnActivitys.get(i).finish();
                        rnActivitys.remove(i);
                    }
                }

            }
            break;
            case UserAgreeChecked: {

                MainApplication.getMainApplication().setUserAgreeChecked(true);

                String deviceNo = SharedPreferencesUtils.getInstance().getUment_String("deviceToken", null);
                if (!TextUtils.isEmpty(deviceNo) && UmengUtils.isInitialized()) {
                    HashMap<String, Object> hashMap1 = new HashMap<>();
                    try {
                        hashMap1.put("result", "success");
                        promise.resolve(new Gson().toJson(hashMap1));
                    } catch (Throwable e) {
                        e.printStackTrace();
                        promise.reject(e);
                    }

                } else {
                    try {
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                LoadingUtils.getLoadingUtils(reactContext.getCurrentActivity()).showLoading();

                                UmengUtils.initUmeng(MainApplication.getContext(), new UmengUtils.UmengListener() {
                                    @Override
                                    public void onTokenSuccess() {
                                        HashMap<String, Object> hashMap = new HashMap<>();
                                        try {
                                            handler.post(new Runnable() {
                                                @Override
                                                public void run() {
                                                    LoadingUtils.getLoadingUtils(reactContext.getCurrentActivity()).dismissLoading();
                                                    ALog.e("oakkkk", "get umeng: " + DevicesUtils.getDeviceNo());
                                                }
                                            });
                                            hashMap.put("result", "success");
                                            promise.resolve(new Gson().toJson(hashMap));
                                        } catch (Throwable e) {
                                            e.printStackTrace();
                                            promise.reject(e);
                                        }
                                    }

                                    @Override
                                    public void onTokenFailure() {
                                        HashMap<String, Object> hashMap = new HashMap<>();
                                        try {
                                            handler.post(new Runnable() {
                                                @Override
                                                public void run() {
                                                    LoadingUtils.getLoadingUtils(reactContext.getCurrentActivity()).dismissLoading();
                                                }
                                            });
                                            hashMap.put("result", "failure");
                                            promise.resolve(new Gson().toJson(hashMap));
                                        } catch (Throwable e) {
                                            e.printStackTrace();
                                            promise.reject(e);
                                        }
                                    }
                                });
                            }
                        });
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
                if (!ThreeSDKInitUtils.getInstance().isIsInitialized()) {
                    try {
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                ALog.e("oakkk", "init three SDK UserAgreeChecked!");
                                ThreeSDKInitUtils.getInstance().init(AppBase.getApplication());
                            }
                        });

                    } catch (Throwable ignored) {

                    }
                }
            }
            break;
            case "showPrivacyDialog": {
                String showPrivacyDialog = SharedPreferencesUtils.getInstance().getUment_String("showPrivacyDialog", null);
                if (TextUtils.isEmpty(showPrivacyDialog)) {
                    SharedPreferencesUtils.getInstance().saveUment("showPrivacyDialog", "alreadyShow");
                    HashMap<String, Object> hashMap1 = new HashMap<>();
                    try {
                        hashMap1.put("result", true);
                        promise.resolve(new Gson().toJson(hashMap1));
                    } catch (Throwable e) {
                        e.printStackTrace();
                        promise.reject(e);
                    }
                }
            }
            break;
            case "RnToNativeEditHealthPage": {
                int pageType = readableMap.getInt("type");
                String id = readableMap.getString("id");
                String inquiringPatientId = readableMap.getString("inquiringPatientId");
                switch (pageType) {
                    case 0: {
                        String weight = readableMap.getString("weight");
                        String height = readableMap.getString("height");
                        ARouter.getInstance().build(ARouterConstants.RecordWeightActivity)
                                .withInt("inquiringPatientId", Integer.valueOf(inquiringPatientId))
                                .withFloat("weight", (weight == null || weight.equals("null")) ? 0 : Float.valueOf(weight))
                                .withInt("height", (height == null || height.equals("null")) ? 0 : Integer.valueOf(height))
                                .withInt("id", (id == null || id.equals("null")) ? 0 : Integer.valueOf(id))
                                .withInt("pageType", pageType)
                                .navigation();
                        break;
                    }
                    case 1: {
                        ARouter.getInstance().build(ARouterConstants.RecordWeightActivity)
                                .withInt("inquiringPatientId", Integer.valueOf(inquiringPatientId).intValue())
                                .withInt("pageType", pageType)
                                .navigation();
                        break;
                    }
                }
            }
            break;
            case "medicalGuidelines": {
                //用药指导
                String orderId = "";
                if (readableMap.hasKey("orderId")) {
                    orderId = readableMap.getString("orderId");
                }
                if (!TextUtils.isEmpty(orderId)) {
                    ARouter.getInstance().build(ARouterConstants.DirectionUsingMedicineActivity)
                            .withString("orderId", orderId)
                            .navigation();
                }
            }
            break;
            case "openHealthConsultDetail": {
                String rowKey = "";
                int rowType = -1;
                if (dataString != null) {
                    try {
                        JSONObject openHealthConsultDetailJSON = new JSONObject(dataString);
                        rowKey = openHealthConsultDetailJSON.getString("rowKey");
                        rowType = openHealthConsultDetailJSON.getInt("type");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                if (TextUtils.isEmpty(rowKey) || "".equals(rowKey)) {

                } else if (rowType == -1) {

                } else {
                    ARouter.getInstance().build(ARouterConstants.HealthConsultDetailActivity)
                            .withString("rowKey", rowKey)
                            .withInt("rowType", Integer.valueOf(rowType).intValue())
                            .navigation();
                }
            }
            break;
            case "GetLocation": {
                promise.resolve(AMapLocationUtils.getLocalString());
            }
            break;
            case "GroupVCPush": {
                String pageTag = "";
                if (readableMap.hasKey("pageTag")) {
                    pageTag = readableMap.getString("pageTag");
                }
                if (readableMap.hasKey("orderNo")) {
                    String orderNo = readableMap.getString("orderNo");
                    ARouter.getInstance().build(ARouterConstants.ConversationActivity)
                            .withBoolean("isInquiryRecord", false)
                            .withInt("chatTypeStatus", 1)
                            .withString("externalOrderNo", orderNo)
                            .navigation();
                    //如果是提交问诊信息页面 需要关闭 返回则是订单列表页面
                    if ("Inquiry1".equals(pageTag) && reactContext.getCurrentActivity() instanceof RNActivity) {
                        reactContext.getCurrentActivity().finish();
                    }
                }
            }
            break;
            case "getAllFunctionKey": {
                JSONObject openJson = new JSONObject();
                try {
                    openJson.put("isOpenGroup", ProjectConfigure.Open.isOpenGroup);
                    openJson.put("Environment", HttpUtils.getUrl());
                } catch (JSONException e) {
                    promise.reject(e);
                    e.printStackTrace();
                }
                promise.resolve(openJson.toString());
            }
            break;
            case "getPromoteResource": {
                if (reactContext != null && reactContext.getCurrentActivity() != null && reactContext.getCurrentActivity() instanceof RNActivity) {
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
//                            ((RNActivity) reactContext.getCurrentActivity()).showPopBall();
                            try {
                                FrameLayout frameLayout = (FrameLayout) LayoutInflater.from(reactContext.getCurrentActivity()).inflate(R.layout.layout_suspended_ball, ((FrameLayout) reactContext.getCurrentActivity().getWindow().getDecorView().findViewById(android.R.id.content)));
                                SuspendedBallView ballView = frameLayout.findViewById(R.id.suspended_ball_view);
                                ballView.isHiddenSuspendedBallView(2, new SuspendedBallView.HiddenCallBack() {
                                    @Override
                                    public void hidden(boolean hidden) {
                                        if (hidden) {
                                            ballView.setVisibility(View.GONE);
                                        } else {
                                            ballView.setVisibility(View.VISIBLE);
                                        }
                                    }

                                    @Override
                                    public void setIcon(String iconUrl) {
                                        if (iconUrl != null) {
                                            ballView.setGifIcon(iconUrl);
                                        } else {
                                            ballView.setGifIcon(R.drawable.icon_default_square);
                                        }
                                    }

                                    @Override
                                    public void getUrl(String url) {
                                        ballView.setActivityUrl(url);
                                    }
                                });

                                ClickUtils.setFastOnClickListener(ballView, new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        ballView.show();
                                    }
                                });
                            } catch (Throwable throwable) {
                                ALog.e("okhttp:", "showPopBall error: " + throwable.getMessage());
                                throwable.printStackTrace();
                            }
                        }
                    });
                }
            }
            break;
            case "toJumpShopCar": {
                ActivityManagerUtils.finishAllActivity();
                Intent intent1 = new Intent(reactContext.getCurrentActivity(), MainActivity.class);
                if (ProjectConfigure.Open.isShowMall) {
                    intent1.putExtra("toJumpMain", 3);
                } else {
                    intent1.putExtra("toJumpMain", 2);
                }
                reactContext.getCurrentActivity().startActivity(intent1);
            }
            break;
            case "toJumpWebApi": {
                RequestParams params = new RequestParams();
                params.put("webApi", HttpUtils.getWebUrl());
                promise.resolve(params.toString());
            }
            break;
            case POP2: {
                int i = 1;
                i = readableMap.getInt("pageNumber");
                reactContext.getCurrentActivity().finish();
            }
            break;
            case "downloadPDF": {
                //PDF TO PICTURE
                JSONObject jsonObject = new JSONObject();
                String pdfUrl = readableMap.getString("url");
                PDFUtils.getPDFUtils().pdf2img(reactContext.getCurrentActivity(), pdfUrl, new HttpCallBack<String>() {
                    @Override
                    public void onSuccess(String resultMsg, int code) {
                        try {
                            PDFUtils.getPDFUtils().PDF2BitMap(resultMsg);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        try {
                            jsonObject.put("result", true);
                            jsonObject.put("msg", "保存到相册成功");
                            promise.resolve(jsonObject.toString());
                        } catch (JSONException e) {
                            promise.reject(e);
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(String s, int i) {
                        try {
                            jsonObject.put("result", false);
                            jsonObject.put("msg", "下载失败");
                            promise.resolve(jsonObject.toString());
                        } catch (JSONException e) {
                            promise.reject(e);
                            e.printStackTrace();
                        }
                    }

                });
            }
            break;
            case "isHaveWeChat": {
                JSONObject jsonObjectWX = new JSONObject();
                if (!CommonUtils.isWeixinAvilible(AppBase.getApplication())) {
                    promise.resolve(false);
                } else {
                    promise.resolve(true);
                }

            }
            break;
            case EXPLAIN_ACTION: {
                String commodityId = "";
                String commodityType = "drug";
                if (readableMap.hasKey("commodityId")) {
                    commodityId = readableMap.getString("commodityId");
                }
                if (readableMap.hasKey("commodityType")) {
                    commodityType = readableMap.getString("commodityType");
                }

                if (!TextUtils.isEmpty(commodityId)) {
                    ARouter.getInstance().build(ARouterConstants.message.GuideVideoActivity)
                            .withString("commodityType", commodityType)
                            .withString("commodityId", commodityId)
                            .navigation();
                }

            }
            break;
            case CLICK_PUSH_MESSAGE: {
                ReadableMap msgInfoObj = readableMap.getMap(AllStringConstants.info);
                if (msgInfoObj != null) {
                    try {
                        if (msgInfoObj.hasKey("scheme")) {
                            String scheme = msgInfoObj.getString("scheme");
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    boolean isJumpLive = MediaCountyManager.getInstance().pageClick(scheme);
                                    ALog.e("oakkk", "isJumpLive: " + isJumpLive);
                                    if (!isJumpLive) {
                                        PushMessageUtil.getInstance().dealMessage(reactContext.getCurrentActivity(), scheme);
                                    }
//                                   PushMessageUtil.getInstance().dealMessage(reactContext.getCurrentActivity(),scheme);
                                }
                            });
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            }
            break;
            case "RNSelectTheAPI": {
                if (!BuildConfig.OPEN_RN_DEBUG) {
                    return;
                }
                String[] apis = {"d1", "t1", "t2", "spare", "api"};
                AlertDialogManager.builder()
                        .setContext(reactContext.getCurrentActivity())
                        .setType(1)
                        .setNegativeButton("取消" + "(当前环境:)" + apis[HttpUtils.getEnvironmentNo()])
                        .setBottomLists(apis)
                        .setBottomItemCallback(new AlertDialogimpl() {
                            @Override
                            public void Success(int i, String s) {
                                super.Success(i, s);
                                switch (i) {
                                    case 0:
                                        MainApplication.LocalDominNo = 0;
                                        break;
                                    case 1:
                                        MainApplication.LocalDominNo = 1;
                                        break;
                                    case 2:
                                        MainApplication.LocalDominNo = 2;
                                        break;
                                    case 3:
                                        MainApplication.LocalDominNo = 3;
                                        break;
                                    case 4:
                                        MainApplication.LocalDominNo = 4;
                                        break;
                                    default:

                                        break;
                                }
                                MediaCountyManager.getInstance().launchInit((Application) MainApplication.getContext());
                                MessageHelper.getMessageHelper().init(reactContext.getCurrentActivity(), BuildConfig.OPEN_LOG_OUT);
                                AlertDialogManager.dismiss();
                                ALog.e(HttpUtils.getUrl() + "");
                            }
                        })
                        .show();
            }
            break;
            case "WXReplaceHead": {
                if (!CommonUtils.isWeixinAvilible(MainApplication.getContext())) {
                    Toast.makeText(reactContext, "微信未安装，请先安装微信", Toast.LENGTH_SHORT).show();
                    return;
                }
                WXEntryActivity.changeImageAvator = true;
                SendAuth.Req req = new SendAuth.Req();
                req.scope = "snsapi_userinfo";
                req.state = "wechat_sdk_demo_test";
                WXEntryActivity.setCallBack(new HttpCallBack<String>() {
                    @Override
                    public void onSuccess(String s, int i) {
                        ALog.e("wechatInfo" + s);
                        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                        stringObjectHashMap.put("result", true);
                        stringObjectHashMap.put("data", s);
                        promise.resolve(CommonUtils.getModuleCommonUtils().GsontoString(stringObjectHashMap));
                    }

                    @Override
                    public void onFailure(String s, int i) {

                    }
                });
                MainApplication.iwxapi.sendReq(req);
            }
            break;
            case "toDoctorHealthDetail": {
                DoctorHealthBean.DataBean dataBean = new Gson().fromJson(dataString, DoctorHealthBean.DataBean.class);
                boolean showInfo = true;
                if (readableMap.hasKey("showInfo")) {
                    showInfo = readableMap.getBoolean("showInfo");
                }
                ARouter.getInstance()
                        .build(ARouterConstants.Home.DoctorHealthActivity)
                        .withInt("id", dataBean.getId())
                        .withBoolean("showInfo", showInfo)
                        .navigation();
            }
            break;
        }
        //rnactivity回调
        toNativeGeneralActionEventListener = new BaseActivityEventListener() {
            @Override
            public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
                super.onActivityResult(activity, requestCode, resultCode, data);
                if (requestCode == REQUEST_CODE_ADDRESS && data != null) {
                    PoiInfo poiInfo = (PoiInfo) data.getSerializableExtra("address");
                    ALog.e("oakkk", "poi info: " + new Gson().toJson(poiInfo));
                    if (poiInfo != null) {
                        JSONObject result = new JSONObject();
                        try {
                            result.put("address", poiInfo.address + poiInfo.name);
//                            result.put("province", poiInfo.province);
                            if (!TextUtils.isEmpty(poiInfo.province) && poiInfo.province.endsWith("市")) {
                                result.put("province", poiInfo.province.substring(0, poiInfo.province.length() - 1));
                            } else {
                                result.put("province", poiInfo.province);
                            }
                            result.put("city", poiInfo.city);
                            if (TextUtils.isEmpty(poiInfo.district)) {
                                poiInfo.district = poiInfo.city;
                            }
                            result.put("district", poiInfo.district);
                            result.put("location_lat", poiInfo.location_lat);
                            result.put("location_lng", poiInfo.location_lng);
                            ALog.e("oakkk", "poi result: " + result.toString());
                            promise.resolve(result.toString());
                        } catch (JSONException e) {
                            e.printStackTrace();
                            promise.reject(e);
                        }
                    }
                }
                reactContext.removeActivityEventListener(toNativeGeneralActionEventListener);
            }
        };
        reactContext.addActivityEventListener(toNativeGeneralActionEventListener);
    }

    private void toSavePicture(String imgUrl, @NonNull ReactContext reactContext, JSONObject jsonObject, @NonNull Promise promise) {
        try {
            //  获取当前程序路径
            String picture = System.currentTimeMillis() + ".jpg";
            Bitmap bitmap = BitmapUtils.GetImageInputStream(imgUrl);
            MediaStore.Images.Media.insertImage(reactContext.getContentResolver(), bitmap, picture, "暂无");
            //获得SD卡根目录路径
            File externalStorageDirectory = Environment.getExternalStorageDirectory();
            String sdpath = externalStorageDirectory.getAbsolutePath();
            ALog.i("sdpath", "toNativeGeneralAction: " + sdpath + "/Pictures/" + picture);
            jsonObject.put("result", true);
            jsonObject.put("msg", "保存图片成功");
            jsonObject.put("filePath", sdpath + "/Pictures/" + picture);
            promise.resolve(jsonObject.toString());
        } catch (Throwable e) {
            e.printStackTrace();
            try {
                jsonObject.put("result", false);
                jsonObject.put("msg", "保存图片失败");
                jsonObject.put("filePath", "");
                promise.resolve(jsonObject.toString());
            } catch (JSONException jsonException) {
                jsonException.printStackTrace();
            }
        }
    }

    void havaCitySearch(Activity mActivity, String city, String searchText, Promise promise) {
        int currentPage = 0;
        ALog.e("oakkkk", "do search query: " + city);
        PoiSearch.Query query = new PoiSearch.Query(searchText, "", city);// 第一个参数表示搜索字符串，第二个参数表示poi搜索类型，第三个参数表示poi搜索区域（空字符串代表全国）
        query.setCityLimit(false);
        query.setPageSize(20);
        query.setPageNum(currentPage);

        PoiSearch poiSearch = new PoiSearch(mActivity, query);
        poiSearch.setOnPoiSearchListener(new PoiSearch.OnPoiSearchListener() {
            @Override
            public void onPoiSearched(PoiResult poiResult, int i) {
                ALog.e("oakkk2", " " + poiResult);
                List<PoiItem> poiItems = poiResult.getPois();
                List<AddressEntity> addressList = new ArrayList<>();
                for (int j = 0; j < poiItems.size(); j++) {
                    AddressEntity data = new AddressEntity();
                    data.setTitle(poiItems.get(j).getTitle());
                    data.setAddress(poiItems.get(j).getAdName() + poiItems.get(j).getSnippet());
                    data.setLat(poiItems.get(j).getLatLonPoint().getLatitude() + "");
                    data.setLng(poiItems.get(j).getLatLonPoint().getLongitude() + "");
                    addressList.add(data);
                }
                HashMap<String, Object> resultMap = new HashMap<>();
                resultMap.put("result", true);
                resultMap.put("data", addressList);
                promise.resolve(CommonUtils.getModuleCommonUtils().getMaptoJson(resultMap));
            }

            @Override
            public void onPoiItemSearched(PoiItem poiItem, int i) {
                ALog.e("oakkk2", " " + poiItem);
            }
        });
        poiSearch.searchPOIAsyn();
    }

    /**
     * 没有地址情况的poi搜索
     */
    private void noCitySearch(Activity mActivity, String searchText, Promise promise) {
        AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
        mLocationOption.setOnceLocation(true);
        mLocationOption.setOnceLocationLatest(true);
        //初始化定位
        AMapLocationClient mLocationClient = new AMapLocationClient(MainApplication.getContext());
        AMapLocationListener mAMapLocationListener = new AMapLocationListener() {
            @Override
            public void onLocationChanged(AMapLocation amapLocation) {
                if (amapLocation != null) {
                    if (amapLocation.getErrorCode() == 0) {
//可在其中解析amapLocation获取相应内容。
                        amapLocation.getLatitude();//获取纬度
                        amapLocation.getLongitude();//获取经度
                        amapLocation.getCity();//城市信息
                        JSONArray newArray = new JSONArray();
                        newArray.put(amapLocation.getCity());
                        newArray.put(amapLocation.getLatitude() + "");
                        newArray.put(amapLocation.getLongitude() + "");
                        String address = amapLocation.getAddress();
                        String province = amapLocation.getProvince();
                        String city = amapLocation.getCity();
                        String district = amapLocation.getDistrict();
                        String street = amapLocation.getStreet();
                        double latitude = amapLocation.getLatitude();
                        double longitude = amapLocation.getLongitude();
                        havaCitySearch(mActivity, city, searchText, promise);
                    }
                } else {
                    //定位失败时，可通过ErrCode（错误码）信息来确定失败的原因，errInfo是错误信息，详见错误码表。
//                    Toast.makeText(getApplicationContext(),"定位获取失败,请检查是否开启定位权限",Toast.LENGTH_SHORT).show();
                }
            }
        };
//设置定位回调监听
        mLocationClient.setLocationListener(mAMapLocationListener);
        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption);
//启动定位
        mLocationClient.startLocation();
    }


    /**
     * 播放语音
     *
     * @param reactContext
     * @param readableMap
     * @param promise
     */
    MediaPlayer mediaPlayer = null;
    Uri uri = null;

    @Override
    public void sendMessageVoice(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {

        ALog.d("sendMessageVoice", "sendMessageVoice: " + readableMap.toString());

        uri = Uri.parse(readableMap.getString("url"));

        if (readableMap.getString("voiceStatus").equals("play")) {
            mediaPlayer = MediaPlayer.create(MainApplication.getContext(), uri);
            if (mediaPlayer.isPlaying()) {
                mediaPlayer.stop();
                mediaPlayer.release();
                mediaPlayer = MediaPlayer.create(MainApplication.getContext(), uri);
            }
            mediaPlayer.start();
        } else if (readableMap.getString("voiceStatus").equals("stop")) {
            if (mediaPlayer != null && mediaPlayer.isPlaying()) {
                mediaPlayer.stop();
                mediaPlayer.release();
            }
        }
        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mediaPlayer) {
                mediaPlayer.stop();
                mediaPlayer.release();
                // 播放完毕
                HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                stringObjectHashMap.put("result", true);//{"result":"success"}
                promise.resolve(new Gson().toJson(stringObjectHashMap));
            }
        });
    }

    @Override
    public void openPhotographPreviewAction(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        ArrayList<ImagesListBean> imagesListBeans = new ArrayList<>();
        int index = readableMap.getInt("index");
        String s = AppReactUtils.INSTANCE.delNativeMap(readableMap.toString());
        try {
            JSONObject jsonObject = new JSONObject(s);
            JSONArray jsonArray = jsonObject.getJSONArray("list");
            for (int i = 0; i < jsonArray.length(); i++) {
                try {
                    imagesListBeans.add(new ImagesListBean((String) jsonArray.get(i)));
                } catch (Exception e) {

                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if (imagesListBeans != null && imagesListBeans.size() != 0 && index >= 0 && index <= imagesListBeans.size()) {
            PreviewBuilder.from(reactContext.getCurrentActivity())
                    .setData(imagesListBeans)
                    .setCurrentIndex(index)
                    .setSingleFling(true)//是否在黑屏区域点击返回
                    .setDrag(true)//是否禁用图片拖拽返回
                    .setType(PreviewBuilder.IndicatorType.Number)//指示器类型
                    .start();//启动
        }


    }


    @Override
    public void openAppletsAction(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        String username = readableMap.getString("username");//小程序username
        String path = readableMap.getString("path");//小程序path

        WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
        req.userName = username; // 填小程序原始id
        req.path = path;//拉起小程序页面的可带参路径，不填默认拉起小程序首页，对于小游戏，可以只传入 query 部分，来实现传参效果，如：传入 "?foo=bar"
        req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版，体验版和正式版
        MainApplication.iwxapi.sendReq(req);
    }

    /**
     * 保存图片
     *
     * @param reactContext
     * @param readableMap
     * @param promise
     */
    @Override
    public void savepicture(@NotNull ReactContext reactContext, @NotNull ReadableMap readableMap, @NotNull Promise promise) {
        ALog.i("savapicture", "" + readableMap.toString());


    }
}
